package com.ruoyi.form.domain;

import java.util.HashMap;
import java.util.Map;

public class ResponseResult {
	public static final String SUCCESS = "200";
	public static final String ERROR = "300";
	public static final String WARN = "300";
	private String statusCode;
	private String message;
	private String tabid;
	private String dialogid;
	private boolean closeCurrent = true;
	private String forward;
	private String forwardConfirm;
	private Map data;

	/**
	 * 静态构造器
	 * @param statusCode
	 * @param message
	 * @param data
	 * @return
	 */
	public static ResponseResult get(String statusCode, String message, Object data) {
		if (data == null) {
			return new ResponseResult(statusCode, message);
		}
		if (data instanceof Map) {
			return new ResponseResult(statusCode, message, (Map) data);
		} else {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("data", data);
			return new ResponseResult(statusCode, message, map);
		}
	}

	/**
	 * 静态构造器
	 * @param msg
	 * @return
	 */
	public static ResponseResult success(String msg) {
		return get(ResponseResult.SUCCESS, msg, null);
	}

	/**
	 * 静态构造器
	 * @param msg
	 * @param data
	 * @return
	 */
	public static ResponseResult success(String msg, Object data) {
		return get(ResponseResult.SUCCESS, msg, data);
	}
	
	/**
	 * 返回操作成功
	 * @return
	 */
	public static ResponseResult success() {
		return get(ResponseResult.SUCCESS, "操作成功", null);
	}

	/**
	 * 静态构造器
	 * @param msg
	 * @return
	 */
	public static ResponseResult error(String msg) {
		return get(ResponseResult.ERROR, msg, null);
	}

	/**
	 * 静态构造器
	 * @param msg
	 * @return
	 */
	public static ResponseResult warn(String msg) {
		return get(ResponseResult.WARN, msg, null);
	}

	public ResponseResult() {
		super();
	}

	public ResponseResult(String statusCode) {
		super();
		this.statusCode = statusCode;
		if (ERROR.equals(statusCode)) {
			this.closeCurrent = false;
		}

	}

	public ResponseResult(String statusCode, String message) {
		super();
		this.statusCode = statusCode;
		this.message = message;
		if (ERROR.equals(statusCode)) {
			this.closeCurrent = false;
		}
	}
	
	public ResponseResult(String statusCode, String message, Map data) {
		super();
		this.statusCode = statusCode;
		this.message = message;
		if (ERROR.equals(statusCode)) {
			this.closeCurrent = false;
		}
		this.data=data;
	}

	public ResponseResult(String statusCode, String message, boolean closeCurrent) {
		super();
		this.statusCode = statusCode;
		this.message = message;
		this.closeCurrent = closeCurrent;
	}

	public ResponseResult(String statusCode, String message, String tabid, String dialogid, boolean closeCurrent,
                          String forward, String forwardConfirm) {
		super();
		this.statusCode = statusCode;
		this.message = message;
		this.tabid = tabid;
		this.dialogid = dialogid;
		this.closeCurrent = closeCurrent;
		this.forward = forward;
		this.forwardConfirm = forwardConfirm;
	}

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getTabid() {
		return tabid;
	}

	public void setTabid(String tabid) {
		this.tabid = tabid;
	}

	public String getDialogid() {
		return dialogid;
	}

	public void setDialogid(String dialogid) {
		this.dialogid = dialogid;
	}

	public boolean isCloseCurrent() {
		return closeCurrent;
	}

	public void setCloseCurrent(boolean closeCurrent) {
		this.closeCurrent = closeCurrent;
	}

	public String getForward() {
		return forward;
	}

	public void setForward(String forward) {
		this.forward = forward;
	}

	public String getForwardConfirm() {
		return forwardConfirm;
	}

	public void setForwardConfirm(String forwardConfirm) {
		this.forwardConfirm = forwardConfirm;
	}

	public Map getData() {
		return data;
	}

	public void setData(Map data) {
		this.data = data;
	}

}
